﻿package mortal.game.view.monthInvestment.view
{
    import Message.DB.Tables.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.utils.*;
    import flash.events.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.mvc.core.*;

    public class monthInvestTypeCellRender extends GCellRenderer
    {
        private var _bg:GImageBitmap;
        private var _item:BaseItem;
        private var _needMoney:GImageBitmap;
        private var _totalReward:GImageBitmap;
        private var _isInvestIcon:GImageBitmap;
        private var _investName:GImageBitmap;
        private var _investBtn:GLoadingButton;
        private var _tinvest:TInvest;
        private var _type:int;

        public function monthInvestTypeCellRender()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gImageBitmap(ImagesConst.MonthInvestTypeBg, 0, 0, this);
            this._item = UICompomentPool.getUICompoment(BaseItem);
            this._item.isShowColorBg = false;
            this._item.x = 46;
            this._item.y = 223;
            this._item.setItemStyle(ItemStyleConst.Big, null, 6, 6);
            this.addChild(this._item);
            this._investName = UIFactory.gImageBitmap("", 20, 24, this, this.setNamePos);
            this._needMoney = UIFactory.gImageBitmap("", 71, 59, this);
            this._totalReward = UIFactory.gImageBitmap("", 90, 137, this, this.setRewardPos);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bg.dispose(param1);
            this._bg = null;
            this._totalReward.dispose(param1);
            this._totalReward = null;
            this._needMoney.dispose(param1);
            this._needMoney = null;
            this._item.dispose(param1);
            this._item = null;
            if (this._investBtn)
            {
                this._investBtn.dispose(param1);
                this._investBtn = null;
            }
            if (this._isInvestIcon)
            {
                this._isInvestIcon.dispose(param1);
                this._isInvestIcon = null;
            }
            this._investName.dispose(param1);
            this._investName = null;
            this._tinvest = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function setRewardPos() : void
        {
            if (isDisposed)
            {
                return;
            }
            this._totalReward.x = this.width - this._totalReward.width >> 1;
            return;
        }// end function

        private function setNamePos() : void
        {
            if (isDisposed)
            {
                return;
            }
            this._investName.x = this.width - this._investName.width >> 1;
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.InvestmentMonth, this._type));
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this._type = param1.type as int;
            this._investName.imgUrl = "monthInvestTypeName_" + this._type + ".png";
            this._needMoney.imgUrl = "MonthInvestNeedMoney_" + this._type + ".png";
            this._totalReward.imgUrl = "MonthInvestTotalReward_" + this._type + ".png";
            this._tinvest = MonthInvestmentConfig.instance.rewardArr[this._type][0] as TInvest;
            if (this._tinvest.reward >= 1000)
            {
                this._item.itemData = new ItemData(this._tinvest.reward);
            }
            else
            {
                this._item.source = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitBigIcon(this._tinvest.reward));
                this._item.toolTipData = GameDefConfig.instance.getEPrictUnitName(this._tinvest.reward);
            }
            var _loc_2:* = MonthInvestmentConfig.instance.getInvestBaseByType(this._type);
            if (InvestUtil.isHasInvestmented(this._type))
            {
                if (this._isInvestIcon == null)
                {
                    this._isInvestIcon = UIFactory.gImageBitmap(ImagesConst.MounthInvestSuccessIcon, 45, 295, this);
                }
                if (this._investBtn)
                {
                    this._investBtn.dispose();
                    this._investBtn = null;
                }
            }
            else
            {
                if (this._isInvestIcon)
                {
                    this._isInvestIcon.dispose();
                    this._isInvestIcon = null;
                }
                if (this._investBtn == null)
                {
                    this._investBtn = UIFactory.gLoadingButton(ResFileConst.MonthInvestBtn, 0, 330, 115, 42, this);
                    this._investBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
                    this._investBtn.move((this.width - this._investBtn.width) * 0.5, 320);
                    this._investBtn.drawNow();
                }
            }
            return;
        }// end function

    }
}
